<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>父组件与子组件</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <cpn2></cpn2>
    </div>

    <script>
      // 创建cpn1子组件
      const cpn1 = Vue.extend({
        template: `
        <div>
          <h2>我是子组件</h2>
          <p>哈哈哈哈</p>  
        </div>
        `,
      });
      // 2. 创建cpn2父组件
      const cpn2 = Vue.extend({
        template: `
        <div>
          <h2>我是父组件</h2>
          <p>嘿嘿嘿嘿</p>
          <cpn1></cpn2>
        </div>
        `,
        components: {
          cpn1: cpn1,
        },
      });
      //创建Vue实例,得到 ViewModel
      var app = new Vue({
        el: "#app",
        data: {},
        methods: {},
        components: {
          cpn2: cpn2,
        },
      });
    </script>
  </body>
</html>
